package d集合.day2.作业;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Test2 {
    public static void main(String[] args) {
        ArrayList arr=new ArrayList();
        LinkedList lk=new LinkedList();
        compare(arr,true);
        compare(lk,true);
        System.out.println("================");
        compare(arr,false);
        compare(lk,false);

    }
    static void compare(List list,boolean isHead){
        long begin=System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            if(isHead){
                list.add(0,i);
            }else {
                list.add(i);
            }
        }
        long end=System.currentTimeMillis();
        String s;
        if(list instanceof ArrayList){
            s="ArrayList";
        }else {
            s="LinkedList";
        }
        String position=isHead?"头部":"尾部";
        System.out.println(s+"在"+position+"添加用时："+(end-begin)+"毫秒");
    }
}
